// ignore_for_file: depend_on_referenced_packages

import 'package:flutter/material.dart';
import 'package:flutter_ability/custom_ui.dart';
import 'package:flutter_ability_example/alert/alerts_page.dart';
import 'package:flutter_ability_example/basis/basis_page.dart';
import 'package:flutter_ability_example/data_display/data_display_page.dart';
import 'package:flutter_ability_example/input/input_page.dart';
import 'package:flutter_ability_example/isolate/isolate_text_page.dart';
import 'package:flutter_ability_example/navigation/navigation_page.dart';
import 'package:flutter_ability_example/utils/color_utils.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: AppPage(),
    );
  }
}

/// 将第一个例子中的Scaffold包裹在AppPage里面
class AppPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    YJSize.init(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text("UI规范-Flutter"),
      ),
      body: Container(
        padding: const EdgeInsets.only(left: 16, right: 16, top: 20),
        child: buildListView(),
      ),
    );
  }

  Widget buildListView() {
    List<String> mList = ["基础", "导航", "数据展示", "输入", "反馈", "业务组件", "ISOLATE"];
    return ListView.builder(
        itemCount: mList.length,
        scrollDirection: Axis.vertical,
        itemBuilder: (context, index) {
          return YJButton(
            size: YJSize.LARGE,
            fullWidthButton: true,
            onPressed: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (ctx) {
                return openPage(index);
                //return NewRoute("abc");
              }));
            },
            text: mList[index],
            color: ColorUtils.getRandomColor(),
            textColor: Colors.white,
          );
        });
  }

  Widget openPage(int index) {
    if (index == 0) {
      return const BasisPage();
    } else if (index == 1) {
      return const NavigationPage();
    } else if (index == 2) {
      return const DataDisplayPage();
    } else if (index == 3) {
      return const InputPage();
    } else if (index == 4) {
      return const AlertsPage();
    } else if (index == 5) {
      return const BasisPage();
    } else if (index == 6) {
      return const IsolateTextPage();
    } else {
      return const BasisPage();
    }
  }

  Widget buildCenter(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        YJButton(
          fullWidthButton: true,
          onPressed: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (ctx) {
              return const BasisPage();
              //return NewRoute("abc");
            }));
          },
          text: "基础",
          color: YJColors.PRIMARY,
          textColor: Colors.white,
        ),
      ],
    );
  }
}
